package cpi.sap.webservice.xmlGenerator;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;

import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;
import cpi.sap.webservice.bean.GetTotalStockOutputBean;

/**
 * For parse xml to java clases
 * @version 1.0 
 * @date  2008-10-15
 * @author jdelgado
 */

public class XMLBaseDAO {
	/**
	 * Parse xml to a java classes
	 * @param xmlConfig xml config
	 * @param xmlRules xml rules for parse
	 * @param objectParsed Object to parse
	 * @throws IOException The files need to open
	 * @throws SAXException The xmls needs to be parse
	 */
	public GetTotalStockOutputBean parse(String xmlConfig, String pathlRules ) throws IOException, SAXException{
		GetTotalStockOutputBean objectParsed = null;
		BufferedReader reader = null;
		Digester digester = null;
		try {
			digester = new Digester();
			digester.addObjectCreate("ZMM_GET_TOTAL_STOCK/OUTPUT", "cpi.sap.webservice.bean.GetTotalStockOutputBean");
			digester.addCallMethod("ZMM_GET_TOTAL_STOCK/OUTPUT/E_AMOUNT","setE_AMOUNT",0);
			objectParsed = (GetTotalStockOutputBean)digester.parse(new StringReader(xmlConfig.toString()));
		} catch (FileNotFoundException fileNotFoundException) {
			fileNotFoundException.printStackTrace();
		} catch(IOException iOException){
			iOException.printStackTrace();
		}catch(SAXException sAXException){
			sAXException.printStackTrace();
		}catch(Exception exception){
			exception.printStackTrace();
		}finally{
			if (reader != null) {
				try {
					reader.close();
				}catch (IOException iOException){
					iOException.printStackTrace();
				}
			}
		}
		return objectParsed;
	}
}
